import http from '@/utils/request'
import type { pickLocationType, shopType, LeaderAddressPage, LeaderAddressPageSearchParams } from '@/types'
import { objToQuery } from '@/utils/helper'

// 获取城市的列表
export const getPickCity = () => http.get<pickLocationType>('/sys/region/findAllList')

export const getShop = (city: string) => http.get<shopType>(`/search/leader/1/3?city=${city}`)

// 选择提货点的商店
export const getSelectShop = (o: { leaderId: number; showLoading?: boolean }) =>
  http.get<null>(`/user/leader/auth/selectLeader/${o.leaderId}?${objToQuery(o)}`)

// 根据经纬度搜索提货点
/**
 * export interface LeaderAddressPageSearchParams {
        page: number // 当前页码
        limit: number // 每页显示条数
        latitude: number // 纬度
        longitude: number // 经度
}

export interface LeaderAddressPage {
  content: shopInterface[] // 提货点内容列表

  totalPages?: number // 总页数

  first?: boolean // 是否第一页

  last: boolean // 是否最后页

  size?: number //  每页显示数量

  empty?: boolean // 是否为空
}

*/
export const getSearchLeaderPage = (o: LeaderAddressPageSearchParams) =>
  http.get<LeaderAddressPage>(`/search/leader/${o.page}/${o.limit}?${objToQuery(o)}`)